/**
 * 获取用户信息
 */
import {getUserinfo} from "../api/CommonApi";


/**
 * 检查并获取用户信息
 */
export default {
    name:'UserInfoMixin',
    data() {
        return {
            userInfo:{}
        }
    },
    methods:{
        checkUserInfo() {
            // 检查如果已登录直接跳转到首页
            if (localStorage.getItem('token') !== '' || localStorage.getItem('token') === undefined || localStorage.getItem('token') === null) {
                getUserinfo().then(res=>{
                    if(res.code === 200) {
                        console.log(res)
                        this.userInfo = res.result;
                    }else{
                        // 默认认为Token失效跳转至登录页面
                        // 移除存储信息
                        localStorage.removeItem('token')
                        this.userInfo = {}
                        // this.$router.push({path:'account/login'})
                    }
                })

            } else {
                console.log('用户未登陆.')
            }
        }
    }
}
